server_url returning variables question
# support
b
server events are confusing to me. how do i return variables that will be used in the script? I tried adding {{ message }} in the opening line and from server_url I'm returning this { "result": "{"message":"Your email has been sent.","email":"test@email.com"}" } but it does not speal the {{ message }} when i call it. i say "tell user that message is {{ message }}" and it doesn't speak it. it definitely visits my server. its the return url format. The docs only explain one use case that does not fit mine at all. i just want to return a simple message right now and have it spoken it says 'maybe you want to specify the assistant based on callers phone number' - I want nothing of the sort, I just want it to be able to reply with some information to the assistant that called it. what is the structure of the data i send back in that case? i just need a simple example.
v
@Bishop It seems like there might be an issue with the way the response data is structured. When you want to return variables to be used in the script, the JSON object should be formatted properly. In your case, the
result
field contains a string that looks like a JSON object, but it's actually not being parsed as JSON because it's enclosed in quotes. Here's how you should structure the data you send back:
Copy code
json
{
  "result": {
    "message": "Your email has been sent.",
    "email": "test@email.com"
  }
}
This way, the
result
field contains an actual JSON object with the properties
message
and
email
. When your server returns this JSON object, the script should be able to access the
message
property and speak it out. So, when you say "tell user that message is {{ message }}", the script should replace
{{ message }}
with the actual message from the response, which is "Your email has been sent." If it's not working as expected, please ensure that the script is correctly parsing the JSON and extracting the
message
variable. If you continue to experience issues, please ask support for more info on this.
You can continue this conversation by mentioning me in the message.
b
ok well i am now sending back this { "result": { "lincolns_birthday": "5/5/25", "email": "test@email.com" } } and in my vapi script i have this your first task is to say this to the caller: "lincolns birthday is {{ lincolns_birthday }}" and when i ask what lincoln's birthday is, it gives the wrong answer (maybe its answering abe lincoln's birthday not my son's birthday) @User
@Vapi { "result": { "lincolns_birthday": "5/5/25", "email": "test@email.com" } } and in my vapi script i have this your first task is to say this to the caller: "lincolns birthday is {{ lincolns_birthday }}" and when i ask what lincoln's birthday is, it gives the wrong answer (maybe its answering abe lincoln's birthday not my son's birthday)
v
@Bishop It appears there might be a misunderstanding in how the data is being returned and used in your VAPI script. The JSON response you're sending back looks correct:
Copy code
json
{
  "result": {
    "lincolns_birthday": "5/5/25",
    "email": "test@email.com"
  }
}
However, to ensure that the VAPI script uses the
lincolns_birthday
variable from your server's response, you need to make sure that the script is correctly configured to receive and use this variable. If the script is not speaking the correct birthday, it could be due to a few reasons: 1. The script might not be correctly parsing the
lincolns_birthday
variable from the JSON response. 2. There might be a conflict with a built-in entity or variable that's taking precedence over your custom variable. 3. The script might not be correctly linked to the server response that contains the
lincolns_birthday
variable. To troubleshoot this, please ensure that: - The script is designed to wait for the server response before trying to speak the
lincolns_birthday
variable. - There are no naming conflicts with other entities or variables in your script. - The server URL is correctly configured to receive the HTTP request and send back the response. If you've checked these points and the issue persists, it might be necessary to consult the VAPI documentation for more specific guidance on handling server responses, or reach out to the support team for assistance with your particular use case.
b
@Vapi the documentation is extremely vague on this point and shows a use case that isn't mine. the examples i have seen go from a phone level server_url that calls the assistant which then of course has the variables already included, that makes sense. can this not be done?
v
@Bishop I understand that the documentation might not cover your specific use case in detail. However, it is indeed possible to return variables from a server to be used in a VAPI script. The key is to ensure that the server response is correctly formatted and that the VAPI script is set up to receive and use the variables from that response. Based on the information you've provided, you are doing it correctly by returning a JSON object with the
result
field containing the variables you want to use. The VAPI script should be able to extract the
lincolns_birthday
variable from the response and use it in the script as you've indicated. If the script is not working as expected, there might be an issue with how the script is handling the server response. Here are a few steps you can take to troubleshoot the issue: 1. Double-check the server URL in the VAPI script to ensure it's pointing to the correct endpoint that returns the JSON response. 2. Verify that the server is correctly handling the request and that the response is being sent with the correct
Content-Type
header (
application/json
). 3. Make sure that the VAPI script is configured to wait for the server response before attempting to use the variables. 4. If there's a caching mechanism, ensure that it's not serving an outdated response. If you've gone through these steps and the issue is still unresolved, it might be best to reach out to the support team with specific details about your implementation. They should be able to provide more targeted assistance for your scenario.
b
this is an assistant server_url call, not phone level, so the assistant is 'static' text inside vapi that's already been called. You said this: Make sure that the VAPI script is configured to wait for the server response before attempting to use the variables. How would I do that?
@Vapi this is an assistant server_url call, not phone level, so the assistant is 'static' text inside vapi that's already been called. You said this: Make sure that the VAPI script is configured to wait for the server response before attempting to use the variables. How would I do that?
@Vapi this is an assistant server_url call, not phone level, so the assistant is 'static' text inside vapi that's already been called. You said this: Make sure that the VAPI script is configured to wait for the server response before attempting to use the variables. How would I do that?
v
@Bishop To ensure that your VAPI script waits for the server response before attempting to use the variables, you would typically use an event handler or a callback function within your script that is triggered upon receiving the server response. This is a common practice in asynchronous programming, where you need to wait for a response from an external source before proceeding. Here's a general outline of the steps you might take: 1. **Send a Request to the Server**: When a certain condition is met or an event occurs in your VAPI script, it should send a request to the server URL you've specified. 2. **Wait for the Response**: The script should not proceed to the next step until it receives a response from the server. This is usually handled by an event listener or a promise that resolves when the response is received. 3. **Process the Response**: Once the response is received, you can extract the variables from the JSON object and use them in your script. 4. **Continue the Script**: With the variables now available, the script can continue to execute, using the data to inform what it says to the caller. In the context of VAPI, this might involve specific syntax or functions provided by the API to handle asynchronous events. If the VAPI documentation does not provide clear examples for this use case, it would be best to reach out to the support team for guidance on how to implement this in your script. They should be able to provide you with the correct syntax and methods to ensure that your script waits for the server response before using the variables. If you need further assistance with this, please ask support for more info on this.
s
@Bishop Assuming your talking about tools calling here.
[prompting]
- Trigger weather tool and map result to the {{weatherInfo}} - - Update user about the message by saying: {{weatherInfo}} message
Do let me know how it goes.